package com.unionfetch.content_home.presenter

import com.unionfetch.content_home.bean.request.FirstStepRequest
import com.unionfetch.content_home.bean.request.SecondStepRequest
import com.unionfetch.content_home.bean.request.ThirdStepIbRequest
import com.unionfetch.content_home.bean.request.ThirdStepRequest
import com.unionfetch.content_home.contract.OpenAccountContract
import com.unionfetch.content_home.model.OpenAccountModel
import com.unionftech.common.base.mvp.IBaseView
import com.unionftech.common.base.mvp.impl.BasePresenter
import com.unionftech.common.base.mvp.impl.IBaseCallBack
import com.unionftech.common.bean.ResponseResult
import com.unionftech.common.common.contract.CommonContract

class OpenAccountPresenter : BasePresenter<IBaseView, OpenAccountModel>(),
    OpenAccountContract.IOpenAccountPresenter {
    override fun submitFirstStep(token: String, request: FirstStepRequest) {
        getView()?.showLoading()
        getModel().handleFirstStep(token, request, object : IBaseCallBack<ResponseResult<Any?>> {
            override fun onResponse(response: ResponseResult<Any?>) {
                getView()?.also { view ->
                    view.hideLoading()
                    if (view is OpenAccountContract.IFirstStepView) {
                        view.handleFirstStep(response)
                    }
                }
            }
        })
    }

    override fun submitSecondStep(token: String, request: SecondStepRequest) {
        getView()?.showLoading()
        getModel().handleSecondStep(token, request, object : IBaseCallBack<ResponseResult<Any?>> {
            override fun onResponse(response: ResponseResult<Any?>) {
                getView()?.also { view ->
                    view.hideLoading()
                    if (view is OpenAccountContract.ISecondStepView) {
                        view.handleSecondStep(response)
                    }
                }
            }
        })
    }

    override fun submitRCThirdStep(token: String, request: ThirdStepRequest) {
        getView()?.showLoading()
        getModel().handleRCThirdStep(token, request, object : IBaseCallBack<ResponseResult<Any?>> {
            override fun onResponse(response: ResponseResult<Any?>) {
                getView()?.also { view ->
                    view.hideLoading()
                    if (view is OpenAccountContract.IThirdStepView) {
                        view.handleThirdStep(response)
                    }
                }
            }
        })
    }

    override fun submitIBThirdStep(token: String, request: ThirdStepIbRequest) {
        getView()?.showLoading()
        getModel().handleIBThirdStep(token, request, object : IBaseCallBack<ResponseResult<Any?>> {
            override fun onResponse(response: ResponseResult<Any?>) {
                getView()?.also { view ->
                    view.hideLoading()
                    if (view is OpenAccountContract.IThirdStepView) {
                        view.handleThirdStep(response)
                    }
                }
            }
        })
    }
}